import os
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
os.environ["QT_SCALE_FACTOR_ROUNDING_POLICY"] = "RoundPreferFloor"

import sys
from PyQt6.QtWidgets import QApplication, QMessageBox
from PyQt6.QtCore import Qt
from ui.main_window import SubtitleTranslator
from utils.installer import TesseractInstaller

def main():
    app = QApplication(sys.argv)
    
    # PyQt6下无需手动设置DPI属性，已默认支持高DPI
    
    # 检查并安装Tesseract-OCR
    installer = TesseractInstaller()
    if not installer.check_installation():
        reply = QMessageBox.question(
            None,
            "安装提示",
            "检测到未安装Tesseract-OCR，是否现在安装？\n（安装过程需要管理员权限）",
            QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
        )
        
        if reply == QMessageBox.StandardButton.Yes:
            if not installer.install():
                QMessageBox.critical(
                    None,
                    "安装失败",
                    "Tesseract-OCR安装失败，请手动安装后重试。"
                )
                return
        else:
            QMessageBox.warning(
                None,
                "警告",
                "未安装Tesseract-OCR将无法使用OCR功能。"
            )
    
    # 创建并显示主窗口
    window = SubtitleTranslator()
    window.show()
    
    sys.exit(app.exec())

if __name__ == "__main__":
    main() 